<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :md="24" :sm="24">
            <span class="table-page-search-submitButtons">
              <!-- <a-button type="primary" @click="exportExcel">硕士统计表</a-button> -->
              <a-button type="primary" @click="exportBsExcel">博士统计表</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <a-table
        ref="table"
        size="default"
        rowKey="key"
        :columns="columns"
        :loading="loading"
        :dataSource="newData"
        :alert="{show: true}"
        :pagination="false"
        bordered
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
      </a-table>
    </a-card>
  </div>
</template>

<script>
  import moment from 'moment'
  import {STable} from '~'
  import {mapState} from 'vuex'

  export default {
    data() {
      return {
        loading: false,
        newData: [],
        advanced: true,
        queryParam: {
        },
        columns: [
          {
            title: '序号',
            scopedSlots: {customRender: 'serial'}
          },
          {
            title: '毕业年月',
            dataIndex: 'byny_',
            customRender: (text, row, index)=> {
              const obj = {
                  children: text,
                  attrs: {},
              };
              if (row.seq >= 1) {   // 第一行数据开始，跨行合并的长度为数据data的长度
                  obj.attrs.rowSpan = row.len;
              }
              if (row.seq >= 2 ) {   // 从第一行往后的所有行表格均合并
                  obj.attrs.rowSpan = 0;
              }

              return obj;
            }
          },
          {
            title: '入学年月',
            dataIndex: 'rxny_'
          },
          // {
          //   title: '学制',
          //   dataIndex: 'xz_'
          // },
          {
            title: '入学总人数',
            dataIndex: 'total'
          },
          {
            title: '毕业率',
            dataIndex: 'byl',
          },
          {
            title: '毕业人数',
            dataIndex: 'byrs'
          },
          {
            title: '延期人数',
            dataIndex: 'yqrs'
          },
        ],
        parameter: {
          pageNo: 1,
          pageSize: 10
        },
        selectMenu: {
          yxList: [],
          years: []
        },
        visible: false,
        init: false
      }
    },
    components: {STable},
    computed: {
      ...mapState({
        TYPE0075: state => state.app['TYPE0075'],
        TYPE0073: state => state.app['TYPE0073'],
        TYPE0503: state => state.app['TYPE0503'],
        TYPE0126: state => state.app['TYPE0126']
      })
    },
    created() {
      this.$store.dispatch('app/setDictionary', 'TYPE0075')
      this.$store.dispatch('app/setDictionary', 'TYPE0073')
      this.$store.dispatch('app/setDictionary', 'TYPE0503')
      this.$store.dispatch('app/setDictionary', 'TYPE0126')
      this.initSelectMenu()
    },
    methods: {
      initSelectMenu() {
        this.init = true
        this.loadData()
      },
      loadData(parameter = {}){
        this.loading = true;
        // this.parameter = parameter
        // parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.queryParam)
        this.$api.cultivate.bsBytj(params).then(res => {
            console.log(res)
            this.newData = []
            res.data.map((item,index) => {
              item.map((it,ind) => {
                  it.seq = ind + 1
                  it.len = item.length
                  this.newData = this.newData.concat(it)
              })
            })
            this.loading = false;
          })
      },
      filterOption(value, op) {
        return op.componentOptions.children[0].text.indexOf(value) !== -1
      },
      yxChange(code) {
        this.$set(this.queryParam, 'zyh', '')
        if (code) {
          this.$api.base.majorAll({lsdwh: code}).then(res => {
            this.$set(this.selectMenu, 'zyList', res.data)
          })
        } else {
          this.$set(this.selectMenu, 'zyList', [])
        }
      },
      // exportExcel() {
      //   let params = {...this.queryParam}
      //   // delete params.pageNum
      //   this.$export('/foster/bygl/bytjExport', params)
      // },
      exportBsExcel() {
        let params = {...this.queryParam}
        delete params.pageNum
        this.$export('/foster/bygl/bsbytjExport', params)
      },
      archive() {
        this.$api.student.archive().then(res => {
          this.$message.success(res.msg)
          $refs.table.refresh(false)
        })
      }
    }
  }
</script>

<style>

</style>
